package utils

import "github.com/antonmedv/expr"

func ExpOn(exp string, argMap map[string]interface{}) (bool, error) {
	if exp == "" {
		return true, nil
	}
	program, err := expr.Compile(exp, expr.Env(argMap), expr.AsBool())
	if err != nil {
		return false, err
	}
	output, rerr := expr.Run(program, argMap)
	if rerr != nil {
		return false, rerr
	}
	return output.(bool), nil
}
